-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[JAVA-SPRING] Convert byte[] to String for operation params [QueryParam; PathParam; HeaderParam; CookieParam; FormParam] #22930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 41 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/api/FakeApi.java">
<violation number="1" location="samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/api/FakeApi.java:383">
P2: @RequestPart is for multipart/form-data, but this endpoint consumes application/x-www-form-urlencoded. The modified parameter still uses @RequestPart, so WebFlux won’t bind the form body correctly (likely 400).</violation>
</file>
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java:944">
P2: Form/multipart DTO still asserts `format: byte` as `byte[]`, but Spring’s default data binding does not Base64‑decode form strings to `byte[]`; it converts the string to raw bytes. This makes form DTO binding inconsistent with the new `String` parameter handling and can yield incorrect values without a custom converter.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...etstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/api/FakeApi.java
Outdated
Show resolved
Hide resolved
.../openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 33 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/server/petstore/springboot-byte-format-edge-cases/src/main/java/org/openapitools/RFC3339DateFormat.java">
<violation number="1" location="samples/server/petstore/springboot-byte-format-edge-cases/src/main/java/org/openapitools/RFC3339DateFormat.java:16">
P2: RFC3339DateFormat hardcodes the delegate StdDateFormat to UTC and does not override setTimeZone, so any configured timezone will be ignored and dates will always format in UTC.</violation>
<violation number="2" location="samples/server/petstore/springboot-byte-format-edge-cases/src/main/java/org/openapitools/RFC3339DateFormat.java:36">
P2: clone() returns the same instance instead of a copy, violating the Format/DateFormat clone contract and preventing callers from obtaining an independent DateFormat instance.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| private static final long serialVersionUID = 1L; | ||
| private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); | ||
|
|
||
| private final StdDateFormat fmt = new StdDateFormat() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: RFC3339DateFormat hardcodes the delegate StdDateFormat to UTC and does not override setTimeZone, so any configured timezone will be ignored and dates will always format in UTC.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/springboot-byte-format-edge-cases/src/main/java/org/openapitools/RFC3339DateFormat.java, line 16:
<comment>RFC3339DateFormat hardcodes the delegate StdDateFormat to UTC and does not override setTimeZone, so any configured timezone will be ignored and dates will always format in UTC.</comment>
<file context>
@@ -0,0 +1,38 @@
+ private static final long serialVersionUID = 1L;
+ private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");
+
+ private final StdDateFormat fmt = new StdDateFormat()
+ .withTimeZone(TIMEZONE_Z)
+ .withColonInTimeZone(true);
</file context>
|
|
||
| @Override | ||
| public Object clone() { | ||
| return this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: clone() returns the same instance instead of a copy, violating the Format/DateFormat clone contract and preventing callers from obtaining an independent DateFormat instance.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/springboot-byte-format-edge-cases/src/main/java/org/openapitools/RFC3339DateFormat.java, line 36:
<comment>clone() returns the same instance instead of a copy, violating the Format/DateFormat clone contract and preventing callers from obtaining an independent DateFormat instance.</comment>
<file context>
@@ -0,0 +1,38 @@
+
+ @Override
+ public Object clone() {
+ return this;
+ }
+}
</file context>
This change updates the generator to correctly map OpenAPI
format: bytefields across all locations.format: byteis generated asString(manual Base64 decoding required).String.format: binary):MultipartFile.byte[], with automatic Base64 decoding via Jackson.application/octet-stream):Resourcefor streaming, no decoding applied.This ensures all
format: bytevalues are correctly typed across parameters and bodies, preserving the distinction between Base64-encoded values and raw binary.The changes are practically limited to
QueryParam; PathParam; HeaderParam; CookieParam; FormParam. But all the other types are asserted as well to prevent accidental regression.fixes #22898
Tests performed:
Verified generated Java files for query, path, header, cookie, form, multipart, JSON body, and binary body fields.
Asserts confirm parameters and properties have the expected types (String, byte[], MultipartFile, Resource).
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Converted byte[] operation parameters to String in the Java Spring generator for query, path, header, cookie, and form params. Spring doesn’t auto-decode base64 here, so we accept the raw base64 string to avoid type issues.
Bug Fixes
Migration
Written for commit e0d2d56. Summary will update on new commits.